package cn.lan.scau_hotel_service.service.impl;

import cn.lan.scau_hotel_service.entity.Order;
import cn.lan.scau_hotel_service.entity.User;
import cn.lan.scau_hotel_service.repository.OrderRepository;
import cn.lan.scau_hotel_service.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderRepository orderRepository;

    @Override
    public Order getOrderById(int id) {
        return orderRepository.getOrderById(id);
    }



    @Override
    public List<Order> getOrderByBooker(User user) {
        return orderRepository.getOrderByBooker(user);
    }

    @Override
    public boolean saveOrder(Order order) {
        return orderRepository.save(order)!=null;
    }

    @Override
    @Transactional
    public boolean deleteOrderById(int id) {
        return orderRepository.deleteOrderById(id)!= 0 ;
    }

    @Override
    public List<Order> findAll() {
        return orderRepository.findAll();
    }

    @Override
    public List<Order> getOrdersByUser(User user) {
        return orderRepository.getOrderByBooker(user);
    }

}
